package org.spring.core.io;

import java.io.FileNotFoundException;
import java.io.InputStream;

import org.spring.util.ClassUtils;

public class ClassPathResource implements Resource {
	private String path;

	private ClassLoader classLoader;

	public ClassPathResource(String path) {
		this(path, null);
	}

	public ClassPathResource(String path, ClassLoader classLoader) {
		this.path = path;
		this.classLoader = classLoader == null ? ClassUtils.getDefaultClassLoader() : classLoader;
	}

	public InputStream getInputStream() throws FileNotFoundException {
		InputStream is = this.classLoader.getResourceAsStream(this.path);
		if (is == null) {
			throw new FileNotFoundException(path + " cannot be opened");
		}
		return is;
		
	}

	public String getDescription() {
		// TODO Auto-generated method stub
		return null;
	}

}
